// 业务处理超时测试
// 服务器达到性能瓶颈，一次业务处理花费了太长时间，超过了设置的非活跃超时时间
// 预估的处理结果是
// 1.这次业务处理完毕后，耗费太长时间，导致其它连接也被连累超时，其它的连接可能会被拖累超时释放

#include <iostream>
#include "../Server/Server.hpp"

int main()
{
    signal(SIGCHLD,SIG_IGN);
    //客户端创建
    for (int i = 0; i < 10; i++)
    {
        pid_t pid = fork();
        if (pid < 0)
        {
            DEBUG_LOG("fork error");
            return 1;
        }
        else if (pid == 0)
        {
            TcpSocket client_socket;
            client_socket.ClientCreate("127.0.0.1", 8080);                 
            std::string req = "GET /hello HTTP/1.1\r\nConnection: keep-alive\r\nContent-Length: 0\r\n\r\n";
            while (true)
            {
                //DEBUG_LOG("准备发送报文");
                assert(client_socket.Send(req.c_str(), req.size()) >= 0);
                char buffer[1024] = {0};
                //DEBUG_LOG("准备接收报文");
                int ret = client_socket.Recv(buffer, sizeof(buffer) - 1);
                if(ret < 0)
                {
                    DEBUG_LOG("Recv Error: %s",strerror(errno));
                    exit(1);
                }        
                DEBUG_LOG("[%s]", buffer);
            }
            client_socket.Close();
            exit(1);
        }        
    }
    while(1) sleep(1);
    return 0;
}